<?php

use yii\helpers\Html;
use yii\grid\GridView;
use wbraganca\videojs\VideoJsWidget;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\EduVideoCourseSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Edu Video Courses';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="edu-video-course-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Edu Video Course', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            [
                'label' => '门店',
                'attribute' => 'dot.room_name',
                'enableSorting' => false,
            ],
            [
                'attribute' => 'title',
                'enableSorting' => false,
            ],
//            'author',
            [
                'attribute' => 'label',
                'enableSorting' => false,
            ],
            [
                'attribute' => 'image',
                'enableSorting' => false,
                'format' => ['image', [
                    'width' => '80',
                    'height' => '80',
                ]],
            ],
            [
                'label' => '视频',
                'attribute' => 'video_url',
                'enableSorting' => false,
                'format' => 'raw',
                'value' => function ($model, $key, $index, $column) {
                    return VideoJsWidget::widget([
                        'options' => [
                            'class' => 'video-js vjs-default-skin vjs-big-play-centered',
                            'poster' => $model->image,
                            'width' => '190',
                            'height' => '120',
                            'controls' => true,
                        ],
                        'jsOptions' => [
                            'preload' => 'auto',
                        ],
                        'tags' => [
                            'source' => [
                                ['src' => $model->video_url, 'type' => 'video/mp4'],
                                ['src' => 'http://vjs.zencdn.net/v/oceans.webm', 'type' => 'video/webm']
                            ],
                            'track' => [
                                ['kind' => 'captions', 'src' => 'http://vjs.zencdn.net/vtt/captions.vtt', 'srclang' => 'en', 'label' => 'English']
                            ]
                        ]
                    ]);
                }
            ],
//            [
//                'attribute' => 'video_url',
//                'enableSorting' => false,
//            ],
            'evalation_count',
            'collect_count',
            'sort',
            'is_free',
            'create_time:datetime',
            //'video_url:url',
            //'label',
            //'price',
            //'is_free',
            //'detail:ntext',
            //'score',
            //'learn_count',
            //'learn_base',
            //'sort',
            //'is_hot',
            //'is_recommend',
            //'create_time:datetime',
            //'update_time:datetime',
            //'status',
            //'evalation_count',
            //'collect_count',
            //'collect_base',
            //'video_time:datetime',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>

<?php
$script = <<< JS
    $(".pagination").append('&nbsp;跳转<input id="invalue" type="text" style="border-radius: 5px;outline: none;border: solid 1px #dddddd;width: 52px;height: 34px;text-align: center;" class="pane"/>页&nbsp;<button id="skip" class="btn btn-default skip ok"">确定</button>');
    
    $('#skip').click(function() {
        var page = $('#invalue').val();
        location.href = "index.php?r=edu-video-course/index&page="+ page;
    });
JS;
$this->registerJs($script);
?>